package com.systemdevelopment.mainproject.View.Admin;

import com.jfoenix.controls.JFXButton;
        import com.jfoenix.controls.JFXTextField;
import com.systemdevelopment.mainproject.Model.Author;
import com.systemdevelopment.mainproject.View.mainUI;
import com.systemdevelopment.mainproject.View.oneInstanceController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
        import javafx.scene.control.Label;

import java.sql.SQLException;
import java.util.HashSet;

public class newAuthorController {

    @FXML
    private JFXButton cancelButton;

    @FXML
    private JFXTextField authorNameField;

    @FXML
    private JFXTextField authorNationField;
    @FXML
    private JFXTextField authorCodeField;


    @FXML
    private JFXButton addAuthorButton;

    @FXML
    private Label Title;



    @FXML
    void addAuthor(ActionEvent event) {
        Author a=new Author();
        a.setName(authorNameField.getText());
        a.setNation(authorNationField.getText());
        a.setCode(authorCodeField.getText());
        HashSet<Author> h= new HashSet<>();
        h.add(a);
        try {
            Author.InsertAuthorIntoDB(h);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            mainUI.loadBackPane();
            ((newBookController) oneInstanceController.getController("newBookController")).initAuthorBox();
        }
    }

    @FXML
    void cancel(ActionEvent event) {
        mainUI.loadBackPane();
    }

}
